package org.dk.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.dk.mapper.TbContentMapper;
import org.dk.pageInfo.PageInfo2;
import org.dk.pojo.TbContent;
import org.dk.service.TbContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class TbContentServiceImpl implements TbContentService {

    @Autowired
    private TbContentMapper tbContentMapper;
    @Override
    public PageInfo2 selectContent(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<TbContent> pageInfo = new PageInfo<>(tbContentMapper.selectByExample(null));
        PageInfo2<TbContent> pageInfo1 = new PageInfo2();
        pageInfo1.setPageNum(pageInfo.getPageNum());
        pageInfo1.setPageSize(pageInfo.getSize());
        pageInfo1.setTotal(pageInfo.getTotal());
        pageInfo1.setList(pageInfo.getList());
        pageInfo1.setLastPage(pageInfo.getPages());
        return pageInfo1;
    }

    @Override
    public void addContent(TbContent content) {
        tbContentMapper.insertSelective(content);
    }

    @Override
    public void deleteContent(Long[] ids) {
        tbContentMapper.deleteContent(ids);
    }

    @Override
    public TbContent selectById(Long id) {
        return tbContentMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateContent(TbContent content) {
        tbContentMapper.updateByPrimaryKeySelective(content);
    }
}
